package com.itshare.video.mapper;

import com.itshare.video.pojo.po.Video;
import com.itshare.video.pojo.po.VideoExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;

public interface VideoMapper {
    long countByExample(VideoExample example);

    int deleteByExample(VideoExample example);

    @Delete({
        "delete from t_video",
        "where video_id = #{videoId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long videoId);

    @Insert({
        "insert into t_video (chapter_title, video_url, ",
        "REVISION, CREATED_BY, ",
        "CREATED_TIME, UPDATED_BY, ",
        "UPDATED_TIME, cover_image_url, ",
        "couse_id, video_message, ",
        "delete_status, user_id, ",
        "category_id, tags, ",
        "look_count, comment_count, ",
        "like_count, collect_count, ",
        "chapter_id, permit_status)",
        "values (#{chapterTitle,jdbcType=VARCHAR}, #{videoUrl,jdbcType=VARCHAR}, ",
        "#{revision,jdbcType=INTEGER}, #{createdBy,jdbcType=VARCHAR}, ",
        "#{createdTime,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=VARCHAR}, ",
        "#{updatedTime,jdbcType=TIMESTAMP}, #{coverImageUrl,jdbcType=VARCHAR}, ",
        "#{couseId,jdbcType=INTEGER}, #{videoMessage,jdbcType=VARCHAR}, ",
        "#{deleteStatus,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, ",
        "#{categoryId,jdbcType=INTEGER}, #{tags,jdbcType=VARCHAR}, ",
        "#{lookCount,jdbcType=INTEGER}, #{commentCount,jdbcType=INTEGER}, ",
        "#{likeCount,jdbcType=INTEGER}, #{collectCount,jdbcType=INTEGER}, ",
        "#{chapterId,jdbcType=INTEGER}, #{permitStatus,jdbcType=INTEGER})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="videoId", before=false, resultType=Long.class)
    int insert(Video record);

    int insertSelective(Video record);

    List<Video> selectByExampleWithRowbounds(VideoExample example, RowBounds rowBounds);

    List<Video> selectByExample(VideoExample example);

    @Select({
        "select",
        "video_id, chapter_title, video_url, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, ",
        "UPDATED_TIME, cover_image_url, couse_id, video_message, delete_status, user_id, ",
        "category_id, tags, look_count, comment_count, like_count, collect_count, chapter_id, ",
        "permit_status",
        "from t_video",
        "where video_id = #{videoId,jdbcType=BIGINT}"
    })
    @ResultMap("com.itshare.video.mapper.VideoMapper.BaseResultMap")
    Video selectByPrimaryKey(Long videoId);

    int updateByExampleSelective(@Param("record") Video record, @Param("example") VideoExample example);

    int updateByExample(@Param("record") Video record, @Param("example") VideoExample example);

    int updateByPrimaryKeySelective(Video record);

    @Update({
        "update t_video",
        "set chapter_title = #{chapterTitle,jdbcType=VARCHAR},",
          "video_url = #{videoUrl,jdbcType=VARCHAR},",
          "REVISION = #{revision,jdbcType=INTEGER},",
          "CREATED_BY = #{createdBy,jdbcType=VARCHAR},",
          "CREATED_TIME = #{createdTime,jdbcType=TIMESTAMP},",
          "UPDATED_BY = #{updatedBy,jdbcType=VARCHAR},",
          "UPDATED_TIME = #{updatedTime,jdbcType=TIMESTAMP},",
          "cover_image_url = #{coverImageUrl,jdbcType=VARCHAR},",
          "couse_id = #{couseId,jdbcType=INTEGER},",
          "video_message = #{videoMessage,jdbcType=VARCHAR},",
          "delete_status = #{deleteStatus,jdbcType=INTEGER},",
          "user_id = #{userId,jdbcType=INTEGER},",
          "category_id = #{categoryId,jdbcType=INTEGER},",
          "tags = #{tags,jdbcType=VARCHAR},",
          "look_count = #{lookCount,jdbcType=INTEGER},",
          "comment_count = #{commentCount,jdbcType=INTEGER},",
          "like_count = #{likeCount,jdbcType=INTEGER},",
          "collect_count = #{collectCount,jdbcType=INTEGER},",
          "chapter_id = #{chapterId,jdbcType=INTEGER},",
          "permit_status = #{permitStatus,jdbcType=INTEGER}",
        "where video_id = #{videoId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Video record);
}